#import "SEGDetailsellManager.h"

#if __has_include(<Commom/SEGModel.h>)
#import <Commom/SEGModel.h>
#else
#import "SEGModel.h"
#endif
#if __has_include(<Commom/SEGHTTPBusinessManager.h>)
#import <Commom/SEGHTTPBusinessManager.h>
#else
#import "SEGHTTPBusinessManager.h"
#endif

static id _detailSellManager;
static dispatch_once_t onceToken;

@implementation SEGDetailsellManager
#pragma mark - SINGLE----BEGIN----
+(instancetype)sharedManager{
    dispatch_once(&onceToken, ^{
        _detailSellManager = [[self alloc] init];
    });
    return _detailSellManager;
}

+(void)destroyResource{
    onceToken = 0;
    _detailSellManager = nil;
}

#pragma mark - SINGLE----END----

#pragma mark - HTTP----BEGIN----
-(void)requestDetailsellWithRentalid:(NSString*)rentalId finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:rentalId forKey:@"rentalId"];
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/bms-api/rental/detailSell",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:GET URLString:urlString parameters:params completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed) {
            finished(isSuccessed,nil,codeType,error.localizedDescription);
            return;
        }
        
        self.detailSell = [SEGDetailsellModel yy_modelWithDictionary:result];
        finished(isSuccessed,result,codeType,error.localizedDescription);
        return;
    }];
}

/**
 房屋租售-出租详情接口
 
 @author Sam
 @param rentalId 房屋租售主键ID
 */
-(void)requestDetailLeaseWithRentalid:(NSString*)rentalId finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:rentalId forKey:@"rentalId"];
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/bms-api/rental/detailLease",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:GET URLString:urlString parameters:params completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed) {
            finished(isSuccessed,nil,codeType,error.localizedDescription);
            return;
        }
        
        self.detailLease = [SEGDetailsellModel yy_modelWithDictionary:result];
        finished(isSuccessed,result,codeType,error.localizedDescription);
        return;
    }];
}

/**
 车位租售详情接口
 
 @author Sam
 @param rentalId 房屋租售主键ID
 */
-(void)requestCarRentalDetailLeaseWithRentalid:(NSString*)rentalId finished:(void(^)(BOOL isSuccessed,SEGCarRentalDetailsDataModel * model,NSString* codeType,NSString* errorMessage))finished {
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:rentalId forKey:@"rentalId"];
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/bms-api/parking/detailParking",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:GET URLString:urlString parameters:params completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed) {
            finished(isSuccessed,nil,codeType,error.localizedDescription);
            return;
        }
        
        SEGCarRentalDetailsDataModel *model = [SEGCarRentalDetailsDataModel yy_modelWithDictionary:result];
        finished(isSuccessed,model,codeType,error.localizedDescription);
        return;
    }];
}



#pragma mark - HTTP----END----

#pragma mark - GETTER----BEGIN----
-(SEGDetailsellModel *)detailSell{
    if (!_detailSell) {
        _detailSell = [[SEGDetailsellModel alloc]init];
    }
    return _detailSell;
}

-(SEGDetailsellModel *)detailLease{
    if (!_detailLease) {
        _detailLease = [[SEGDetailsellModel alloc]init];
    }
    return _detailLease;
}
#pragma mark - GETTER----END----
@end

